import { MessageBox, Message } from 'element-ui';
import targaVue from '../main';

export const ErrorType = {
  Info: '',
  Success: 'success',
  Warning: 'warning',
  Error: 'error'
};

export function targaMessageBox(_this, errInfo, type) {
  var title;
  if (typeof _this === 'string') {
    title = _this;
  } else {
    title = _this.$route.meta.title;
  }
  type = type || 'error'
  MessageBox.alert(errInfo, title, {
    confirmButtonText: targaVue.$t('confirm'),
    type
  });
}

export function targaMessage(message, type) {
  type = type || 'success'
  Message({ showClose: true, message, type });
}

export async function ConfirmMessageBox(errTitle, errInfo, errType) {
  try {
    return await MessageBox.confirm(errInfo, errTitle, {
      confirmButtonText: targaVue.$t('confirm'),
      cancelButtonText: targaVue.$t('cancel'),
      type: errType,
      cancelButtonClass: 'btn-cancel-to-right'
    });
  } catch (e) {
    return e
  }
}
